package com.evan.idempotent.enums;


import com.evan.common.base.BaseEnumInterface;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: 幂等组件的存储数据源类型
 * @Author liudeguang
 */
public enum IdempotentStorageTypeEnum implements BaseEnumInterface<String> {

    REDIS("REDIS", "redis数据源"),
    MYSQL("MYSQL", "mysql数据源"),
    MONGO("MONGO", "mongo数据源"),
    MEMORY("MEMORY", "memory数据源");

    private String code;
    private String desc;

    IdempotentStorageTypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    public final static Map<String, IdempotentStorageTypeEnum> MAP_VALUES = Arrays.stream(IdempotentStorageTypeEnum.values()).collect(Collectors.toMap(e -> e.code, e -> e, (e1, e2) -> e1));

    public static Boolean containCode(String code) {
        return MAP_VALUES.containsKey(code);
    }

    public static IdempotentStorageTypeEnum getByCode(String code) {
        return MAP_VALUES.get(code);
    }
}
